home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.002 / stk-3 / STk-3.1 / Tcl / tclUnixPort.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-31  |  8.5 KB  |  414 lines

  1. /*
  2.  * tclUnixPort.h --
  3.  *
  4.  *    This header file handles porting issues that occur because
  5.  *    of differences between systems.  It reads in UNIX-related
  6.  *    header files and sets up UNIX-related macros for Tcl's UNIX
  7.  *    core.  It should be the only file that contains #ifdefs to
  8.  *    handle different flavors of UNIX.  This file sets up the
  9.  *    union of all UNIX-related things needed by any of the Tcl
  10.  *    core files.  This file depends on configuration #defines such
  11.  *    as NO_DIRENT_H that are set up by the "configure" script.
  12.  *
  13.  *    Much of the material in this file was originally contributed
  14.  *    by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  15.  *
  16.  * Copyright (c) 1991-1994 The Regents of the University of California.
  17.  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
  18.  *
  19.  * See the file "license.terms" for information on usage and redistribution
  20.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  21.  *
  22.  * SCCS: @(#) tclUnixPort.h 1.33 96/03/25 17:15:21
  23.  */
  24.  
  25. #ifndef _TCLUNIXPORT
  26. #define _TCLUNIXPORT
  27.  
  28. #ifndef _TCLINT
  29. #   include "tclInt.h"
  30. #endif
  31. #include <errno.h>
  32. #include <fcntl.h>
  33. #ifdef HAVE_NET_ERRNO_H
  34. #   include <net/errno.h>
  35. #endif
  36. #include <pwd.h>
  37. #include <signal.h>
  38. #include <sys/param.h>
  39. #include <sys/types.h>
  40. #ifdef USE_DIRENT2_H
  41. #   include "../compat/dirent2.h"
  42. #else
  43. #   ifdef NO_DIRENT_H
  44. #    include "../compat/dirent.h"
  45. #   else
  46. #    include <dirent.h>
  47. #   endif
  48. #endif
  49. #include <sys/file.h>
  50. #ifdef HAVE_SYS_SELECT_H
  51. #   include <sys/select.h>
  52. #endif
  53. #include <sys/stat.h>
  54. #if TIME_WITH_SYS_TIME
  55. #   include <sys/time.h>
  56. #   include <time.h>
  57. #else
  58. #   if HAVE_SYS_TIME_H
  59. #       include <sys/time.h>
  60. #   else
  61. #       include <time.h>
  62. #   endif
  63. #endif
  64. #ifndef NO_SYS_WAIT_H
  65. #   include <sys/wait.h>
  66. #endif
  67. #ifdef HAVE_UNISTD_H
  68. #   include <unistd.h>
  69. #else
  70. #   include "../compat/unistd.h"
  71. #endif
  72.  
  73. /*
  74.  * Socket support stuff: This likely needs more work to parameterize for
  75.  * each system.
  76.  */
  77.  
  78. #include <sys/socket.h>        /* struct sockaddr, SOCK_STREAM, ... */
  79. #include <sys/utsname.h>    /* uname system call. */
  80. #include <netinet/in.h>        /* struct in_addr, struct sockaddr_in */
  81. #include <arpa/inet.h>        /* inet_ntoa() */
  82. #include <netdb.h>        /* gethostbyname() */
  83.  
  84. /*
  85.  * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
  86.  */
  87.  
  88. #ifndef O_NONBLOCK
  89. #   define O_NONBLOCK 0x80
  90. #endif
  91.  
  92. /*
  93.  * HPUX needs the flag O_NONBLOCK to get the right non-blocking I/O
  94.  * semantics, while most other systems need O_NDELAY.  Define the
  95.  * constant NBIO_FLAG to be one of these
  96.  */
  97.  
  98. #ifdef HPUX
  99. #  define NBIO_FLAG O_NONBLOCK
  100. #else
  101. #  define NBIO_FLAG O_NDELAY
  102. #endif
  103.  
  104. /*
  105.  * The default platform eol translation on Unix is TCL_TRANSLATE_LF:
  106.  */
  107.  
  108. #define    TCL_PLATFORM_TRANSLATION    TCL_TRANSLATE_LF
  109.  
  110. /*
  111.  * Not all systems declare the errno variable in errno.h. so this
  112.  * file does it explicitly.  The list of system error messages also
  113.  * isn't generally declared in a header file anywhere.
  114.  */
  115.  
  116. extern int errno;
  117.  
  118. /*
  119.  * The type of the status returned by wait varies from UNIX system
  120.  * to UNIX system.  The macro below defines it:
  121.  */
  122.  
  123. #ifdef _AIX
  124. #   define WAIT_STATUS_TYPE pid_t
  125. #else
  126. #ifndef NO_UNION_WAIT
  127. #   define WAIT_STATUS_TYPE union wait
  128. #else
  129. #   define WAIT_STATUS_TYPE int
  130. #endif
  131. #endif
  132.  
  133. /*
  134.  * Supply definitions for macros to query wait status, if not already
  135.  * defined in header files above.
  136.  */
  137.  
  138. #ifndef WIFEXITED
  139. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  140. #endif
  141.  
  142. #ifndef WEXITSTATUS
  143. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  144. #endif
  145.  
  146. #ifndef WIFSIGNALED
  147. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  148. #endif
  149.  
  150. #ifndef WTERMSIG
  151. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  152. #endif
  153.  
  154. #ifndef WIFSTOPPED
  155. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  156. #endif
  157.  
  158. #ifndef WSTOPSIG
  159. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  160. #endif
  161.  
  162. /*
  163.  * Define constants for waitpid() system call if they aren't defined
  164.  * by a system header file.
  165.  */
  166.  
  167. #ifndef WNOHANG
  168. #   define WNOHANG 1
  169. #endif
  170. #ifndef WUNTRACED
  171. #   define WUNTRACED 2
  172. #endif
  173.  
  174. /*
  175.  * Supply macros for seek offsets, if they're not already provided by
  176.  * an include file.
  177.  */
  178.  
  179. #ifndef SEEK_SET
  180. #   define SEEK_SET 0
  181. #endif
  182.  
  183. #ifndef SEEK_CUR
  184. #   define SEEK_CUR 1
  185. #endif
  186.  
  187. #ifndef SEEK_END
  188. #   define SEEK_END 2
  189. #endif
  190.  
  191. /*
  192.  * The stuff below is needed by the "time" command.  If this
  193.  * system has no gettimeofday call, then must use times and the
  194.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  195.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  196.  * some might not even have HZ.
  197.  */
  198.  
  199. #ifdef NO_GETTOD
  200. #   include <sys/times.h>
  201. #   include <sys/param.h>
  202. #   ifndef CLK_TCK
  203. #       ifdef HZ
  204. #           define CLK_TCK HZ
  205. #       else
  206. #           define CLK_TCK 60
  207. #       endif
  208. #   endif
  209. #else
  210. #   ifdef HAVE_BSDGETTIMEOFDAY
  211. #    define gettimeofday BSDgettimeofday
  212. #   endif
  213. #endif
  214.  
  215. #ifdef GETTOD_NOT_DECLARED
  216. EXTERN int        gettimeofday _ANSI_ARGS_((struct timeval *tp,
  217.                 struct timezone *tzp));
  218. #endif
  219.  
  220. /*
  221.  * Define access mode constants if they aren't already defined.
  222.  */
  223.  
  224. #ifndef F_OK
  225. #    define F_OK 00
  226. #endif
  227. #ifndef X_OK
  228. #    define X_OK 01
  229. #endif
  230. #ifndef W_OK
  231. #    define W_OK 02
  232. #endif
  233. #ifndef R_OK
  234. #    define R_OK 04
  235. #endif
  236.  
  237. /*
  238.  * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
  239.  * already defined.
  240.  */
  241.  
  242. #ifndef FD_CLOEXEC
  243. #   define FD_CLOEXEC 1
  244. #endif
  245.  
  246. /*
  247.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  248.  * define "lstat" to use "stat" instead.
  249.  */
  250.  
  251. #ifndef S_IFLNK
  252. #   define lstat stat
  253. #endif
  254.  
  255. /*
  256.  * Define macros to query file type bits, if they're not already
  257.  * defined.
  258.  */
  259.  
  260. #ifndef S_ISREG
  261. #   ifdef S_IFREG
  262. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  263. #   else
  264. #       define S_ISREG(m) 0
  265. #   endif
  266. # endif
  267. #ifndef S_ISDIR
  268. #   ifdef S_IFDIR
  269. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  270. #   else
  271. #       define S_ISDIR(m) 0
  272. #   endif
  273. # endif
  274. #ifndef S_ISCHR
  275. #   ifdef S_IFCHR
  276. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  277. #   else
  278. #       define S_ISCHR(m) 0
  279. #   endif
  280. # endif
  281. #ifndef S_ISBLK
  282. #   ifdef S_IFBLK
  283. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  284. #   else
  285. #       define S_ISBLK(m) 0
  286. #   endif
  287. # endif
  288. #ifndef S_ISFIFO
  289. #   ifdef S_IFIFO
  290. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  291. #   else
  292. #       define S_ISFIFO(m) 0
  293. #   endif
  294. # endif
  295. #ifndef S_ISLNK
  296. #   ifdef S_IFLNK
  297. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  298. #   else
  299. #       define S_ISLNK(m) 0
  300. #   endif
  301. # endif
  302. #ifndef S_ISSOCK
  303. #   ifdef S_IFSOCK
  304. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  305. #   else
  306. #       define S_ISSOCK(m) 0
  307. #   endif
  308. # endif
  309.  
  310. /*
  311.  * Make sure that MAXPATHLEN is defined.
  312.  */
  313.  
  314. #ifndef MAXPATHLEN
  315. #   ifdef PATH_MAX
  316. #       define MAXPATHLEN PATH_MAX
  317. #   else
  318. #       define MAXPATHLEN 2048
  319. #   endif
  320. #endif
  321.  
  322. /*
  323.  * Make sure that L_tmpnam is defined.
  324.  */
  325.  
  326. #ifndef L_tmpnam
  327. #   define L_tmpnam 100
  328. #endif
  329.  
  330. /*
  331.  * The following macro defines the type of the mask arguments to
  332.  * select:
  333.  */
  334.  
  335. #ifndef NO_FD_SET
  336. #   define SELECT_MASK fd_set
  337. #else
  338. #   ifndef _AIX
  339.     typedef long fd_mask;
  340. #   endif
  341. #   if defined(_IBMR2)
  342. #    define SELECT_MASK void
  343. #   else
  344. #    define SELECT_MASK int
  345. #   endif
  346. #endif
  347.  
  348. /*
  349.  * Define "NBBY" (number of bits per byte) if it's not already defined.
  350.  */
  351.  
  352. #ifndef NBBY
  353. #   define NBBY 8
  354. #endif
  355.  
  356. /*
  357.  * The following macro defines the number of fd_masks in an fd_set:
  358.  */
  359.  
  360. #ifndef FD_SETSIZE
  361. #   ifdef OPEN_MAX
  362. #    define FD_SETSIZE OPEN_MAX
  363. #   else
  364. #    define FD_SETSIZE 256
  365. #   endif
  366. #endif
  367. #if !defined(howmany)
  368. #   define howmany(x, y) (((x)+((y)-1))/(y))
  369. #endif
  370. #ifndef NFDBITS
  371. #   define NFDBITS NBBY*sizeof(fd_mask)
  372. #endif
  373. #define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
  374.  
  375. /*
  376.  * The following function is declared in tclInt.h but doesn't do anything
  377.  * on Unix systems.
  378.  */
  379.  
  380. #define TclSetSystemEnv(a,b)
  381.  
  382. /*
  383.  * The following implements the Unix method for exiting the process.
  384.  */
  385. #define TclPlatformExit(status) exit(status)
  386.  
  387. /*
  388.  * The following functions always succeeds under Unix.
  389.  */
  390.  
  391. #define TclHasSockets(interp) (TCL_OK)
  392. #define TclHasPipes() (1)
  393.  
  394. /*
  395.  * Variables provided by the C library:
  396.  */
  397.  
  398. #if defined(_sgi) || defined(__sgi)
  399. #define environ _environ
  400. #endif
  401. extern char **environ;
  402.  
  403. /*
  404.  * At present (12/91) not all stdlib.h implementations declare strtod.
  405.  * The declaration below is here to ensure that it's declared, so that
  406.  * the compiler won't take the default approach of assuming it returns
  407.  * an int.  There's no ANSI prototype for it because there would end
  408.  * up being too many conflicts with slightly-different prototypes.
  409.  */
  410.  
  411. extern double strtod();
  412.  
  413. #endif /* _TCLUNIXPORT */
  414.